/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bookshop.dao;

import com.bookshop.entity.Type;
import com.bookshop.exception.EBookshopException;
import javax.ejb.Singleton;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Caroline
 */
@Singleton(mappedName = "com.bookshop.dao.type")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class DaoTypeImpl implements IDaoTypeLocal, IDaoTypeRemote {
    
    @PersistenceContext
    private EntityManager em;
        
    @Override
    public Type getTypeById(int typeId) {
        try {
            return (Type) em.createNamedQuery("Type.findById").setParameter("id", typeId).getSingleResult();
        } catch(Throwable th) {
            throw new EBookshopException(th.getMessage(), th);
        }
    }

    
}
